package com.codedancer.campus.po;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.codedancer.campus.common.typehandler.CodeEnumTypeHandler;
import com.codedancer.campus.enums.CommodityStatus;
import com.codedancer.campus.enums.ConfessionalWallStatus;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;

import java.io.Serializable;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@TableName(value = "confessional_wall", autoResultMap = true)
@Table(name = "confessional_wall", comment = "表白墙")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ConfessionalWall extends Model<ConfessionalWall> implements Serializable {

    @TableId
    @TableField("uuid")
    @Column(name = "uuid", type = MySqlTypeConstant.VARCHAR, length = 36, isKey = true, isNull = false, comment = "uuid")
    private String uuid;

    @TableField("content")
    @Column(name = "content", type = MySqlTypeConstant.TEXT, isNull = false, comment = "内容")
    private String content;

    @TableField("publish_user_uuid")
    @Column(name = "publish_user_uuid", type = MySqlTypeConstant.VARCHAR, length = 36, isNull = false, comment = "发布人uuid")
    private String publishUserUuid;

    @TableField("publish_school_uuid")
    @Column(name = "publish_school_uuid", type = MySqlTypeConstant.VARCHAR, length = 36, isNull = false, comment = "发布学校uuid")
    private String publishSchoolUuid;

    @TableField("deleted")
    @Column(name = "deleted", type = MySqlTypeConstant.TINYINT, length = 1, isNull = false, comment = "是否删除 1表示删除 0表示未删除", defaultValue = "0")
    private Short deleted;

    @Column(name = "create_time", type = MySqlTypeConstant.DATETIME, isNull = false, comment = "创建时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @Column(name = "update_time", type = MySqlTypeConstant.DATETIME, isNull = false, comment = "更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    @TableField("view_count")
    @Column(name = "view_count", type = MySqlTypeConstant.INT, length = 10, isNull = false, comment = "浏览量", defaultValue = "0")
    private Integer viewCount;

    @TableField("comment_count")
    @Column(name = "comment_count", type = MySqlTypeConstant.INT, length = 10, isNull = false, comment = "评论数量", defaultValue = "0")
    private Integer commentCount;

    @TableField("kudos_count")
    @Column(name = "kudos_count", type = MySqlTypeConstant.INT, length = 10, isNull = false, comment = "点赞数量", defaultValue = "0")
    private Integer kudosCount;

    @TableField("examine_count")
    @Column(name = "examine_count", type = MySqlTypeConstant.INT, length = 1, isNull = false, comment = "审核次数，最多审核五次", defaultValue = "0")
    private Integer examineCount;

    @TableField(value = "status", typeHandler = CodeEnumTypeHandler.class)
    @Column(name = "status", type = MySqlTypeConstant.TINYINT, length = 1, isNull = false, comment = "表白墙状态 1表示待审核 2未通过 3表示通过", defaultValue = "1")
    private ConfessionalWallStatus status;

    @TableField("is_open_comment")
    @Column(name = "is_open_comment", type = MySqlTypeConstant.BIT, isNull = false, comment = "是否开启评论", defaultValue = "true")
    private Boolean isOpenComment;

    @TableField("is_sync_liberty_square")
    @Column(name = "is_sync_liberty_square", type = MySqlTypeConstant.BIT, length = 1, isNull = false, comment = "是否同步到自由广场", defaultValue = "false")
    private Boolean isSyncLibertySquare;

    // 发布人
    @TableField(exist = false)
    private User publishUser;

    // 发布学校
    @TableField(exist = false)
    private School publishSchool;

    /**
     * 审核次数是否大于五次
     *
     * @return
     */
    public boolean examineCountIsGtFive() {
        return examineCount >= 5;
    }
}
